package test

import config.MyFile
import org.apache.commons.io.FileUtils

import scala.io.Source
import scala.jdk.CollectionConverters._

object DealWithVar extends MyFile{


  def main(args: Array[String]): Unit = {
    dealWithSnp
  }

  def dealWithIndel = {
    val path = "H:\\紫花苜蓿数据库\\2023_9_22\\网站"
    val file = s"$path/200.indel.anno.exonic_variant_function".toFile

    Source.fromFile(file).getLines().grouped(100000).foreach { x =>
      x.map(_.split("\t").tail).groupBy(_(2)).foreach { y =>

        FileUtils.writeLines(s"$path/indel/${y._1}.txt".toFile, y._2.map(_.mkString("\t")).toBuffer.asJava, true)
      }
    }
  }

  def dealWithSnp = {
    val path = "H:\\紫花苜蓿数据库\\2023_9_22\\网站"
    val file = s"$path/200.snp.anno.variant_function".toFile

    Source.fromFile(file).getLines().grouped(100000).foreach { x =>
      x.map(_.split("\t")).groupBy(_(2)).foreach { y =>

        FileUtils.writeLines(s"$path/snp/${y._1}.txt".toFile, y._2.map(_.mkString("\t")).toBuffer.asJava, true)
      }
    }
  }

  def dealWithSV = {
    val path = "H:\\紫花苜蓿数据库\\2023_9_22\\网站"
    val file = s"$path/200.SV.anno.variant_function".toFile

    Source.fromFile(file).getLines().grouped(100000).foreach { x =>
      x.map(_.split("\t")).groupBy(_(2)).foreach { y =>

        FileUtils.writeLines(s"$path/sv/${y._1}.txt".toFile, y._2.map(_.mkString("\t")).toBuffer.asJava, true)
      }
    }
  }
}
